<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
<!--		<meta name="viewport" content="width=device-width,initial-scale=1.0">-->
		<title>新增发票抬头</title>
		<link href="css/index.css" rel="stylesheet" />
	</head>
	<body>
		<script type="text/javascript" src="js/jquery.min.js" ></script>
		<script type="text/javascript" src="js/oldPublic.js" ></script>
		<script src="js/pdf.js"></script>
		<script src="js/pdf.worker.js"></script>
		<script src="js/code.js"></script>
		<script src="js/security.js"></script>
		<div class="wrapLookTicket">
		<div id="container" style="width: 100%;height: auto;overflow-x: scroll;">
	        <div class="lightbox"></div>
	        <div id="pop" class="pop">
	            <canvas id="the-canvas" style="width: 100%;"></canvas>
	        </div>
	    </div>
			<a style="height: 1rem;display: block;margin-top: 0.8rem;text-align: center;font-size: 32px;">下载</a>
		</div>
	

<script>
	var login_name = sessionStorage.getItem('login_name');
	var telphone = sessionStorage.getItem('telphone');
	var orgcode = sessionStorage.getItem('orgcode');
		var locationUrl = window.location.href;
		var invoice_code = locationUrl.split('?')[1].split('&')[0].split('=')[1];
		var invoice_date = locationUrl.split('?')[1].split('&')[1].split('=')[1];
		var invoice_no = locationUrl.split('?')[1].split('&')[2].split('=')[1];
		var sum_amt = locationUrl.split('?')[1].split('&')[3].split('=')[1];
			$.ajax({
				type:"post",
				url:sessionStorage.getItem('ipconfig'),
				data:JSON.stringify({data:encryptByDESModeEBC(JSON.stringify({"tag": "9108", 'login_name': login_name, 'invoice_code': invoice_code, 'invoice_date': invoice_date, 'invoice_no': invoice_no, 'sum_amt': sum_amt,'orgcode':orgcode}))}),
				contentType: "application/json;charset=utf-8",
				success:function(data){
					console.log(data);
					if(data.result=='00'){
						var pdfUrl = data.fpurl;
						$('.wrapLookTicket a').attr('download',pdfUrl);
						console.log(data.fpbyte);
						 	var pdfBase = data.fpbyte;
						    pdfBase = pdfBase.replace(/[\n\r]/g, '');
					        var pdfData = atob(pdfBase);
					        showPdf(pdfData);
						
					}else{
						showWarn(data.description);
					}
				}
			});
			
			
				function showPdf(a){
						PDFJS.workerSrc = './js/pdf.worker.js';
						PDFJS.cMapUrl= 'https://cdn.jsdelivr.net/npm/pdfjs-dist@2.0.288/cmaps/'
						PDFJS.cMapPacked= true
						var loadingTask = PDFJS.getDocument({data: a});
						loadingTask.promise.then(function(pdf) {
					    console.log('PDF loaded');
					  
					    var pageNumber = 1;
					    pdf.getPage(pageNumber).then(function(page) {
					    console.log('Page loaded');
					    
					    var scale = 1.5;
					    var viewport = page.getViewport(scale);
					
					    var canvas = document.getElementById('the-canvas');
					    var context = canvas.getContext('2d');
					    canvas.height = viewport.height;
					    canvas.width = viewport.width;
					
					    var renderContext = {
					      canvasContext: context,
					      viewport: viewport
					    };
					    var renderTask = page.render(renderContext);
					    renderTask.then(function () {
					      console.log('Page rendered');
					    });
					  });
					}, function (reason) {
					  console.error(reason);
					});
					$('#container').show()
					}	
		
</script>

</body>
</html>
